package com.xiaoyi.tool;

import com.xiaoyi.entity.XyData;
import com.xiaoyi.tool.http.HostConfig;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * @author Aivin , on 2018/12/27.
 */

public class UrlTool {

    private static String enCode(String str1){
        String  reslut ="";
        try {
              reslut=URLEncoder.encode(str1 ,"utf-8") ;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        // 解决 空格 被转为 + 的问题
        reslut=reslut. replaceAll("\\+",  "%20") ;
        return  reslut ;
    }

    /**
     * http://192.168.23.3:8080/xyData/%E5%90%AF%E5%8A%A8%E9%A1%B5/%E9%A3%8E%E6%99%AF/0002.jpg
     */
    public static String getDataLastUrl(XyData xyData  ){
        String  reslut=  HostConfig.HOST_IP+  "xyData/"  +
                enCode(xyData.getmType()) + "/" +
                enCode(xyData.getmDir()) + "/"  +
                enCode(xyData.getmUrl1());
        return reslut ;
    }

    public static String getLrcUrl(XyData xyData ){
        String  reslut=  HostConfig.HOST_IP+  "xyData/"  +
                enCode(xyData.getmType()) + "/" +
                enCode(xyData.getmDir()) + "/"  +
                enCode(xyData.getmLrc());
        return reslut ;
    }
}
